/**
 * [OElove] (C)2010-2099 OELOVE.COM Inc. X
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2017/03/23 by CL $
*/
var SHADE_BOX_ID = "myrz";
$(function(){ 
	
	//打开认证页面
	$(document).on("click", "[f='but_open_rz']", function(){
		$_type = $(this).attr("data-type");
		if (typeof($_type) == "undefined") {
			$_type = "mobile";
		}
		$ajax_url = _OE_FILE + "&c=rz&a=rz&type="+$_type;
		if ($_type == "idnumber") {
			oeShadeBox(SHADE_BOX_ID, "ajax", $ajax_url, 500, 310);
		}
		else {
			oeShadeBox(SHADE_BOX_ID, "ajax", $ajax_url, 500, 240);
		}
	});


	//获取手机验证码
	$(document).on("click", "[f='send_mobilecode']", function(){
		$val_mobile = $("#mobile").val();
		if (!isMobile($val_mobile)) {
			ToastShow("请填写有效的手机号码");
			return false;
		}
		$(this).html("获取中...");
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz&a=send",
			cache: false,
			data: {send_type:"mobile", name:$val_mobile, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("发送成功，请查收手机短信！");
					_countDown("btn_send_mobilecode", "send_mobilecode");
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("发送失败，请检查手机号码");
					}
					$("#btn_send_mobilecode").html("获取验证码");
				}

			},
			error: function() {
				//ToastShow("系统繁忙，请稍后再试");
				$("#btn_send_mobilecode").html("获取验证码");
			}
		});

	});

	//手机认证
	$(document).on("click", "[f='but_confirm_mobile_rz']", function(){
		$mobile = $("#mobile").val();
		$mobilecode = $("#mobilecode").val();
		if (!isMobile($mobile)) {
			ToastShow("请填写有效的手机号码");
			return false;
		}
		if ($mobilecode.length == 0) {
			ToastShow("请填写手机验证码");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz",
			cache: false,
			data: {a:"mobilerz", mobile:$mobile, mobilecode:$mobilecode, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("认证成功");
					_closeShadeBox(SHADE_BOX_ID, function(){
						window.location.reload();
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("认证失败，请检查！");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


	//获取邮箱验证码
	$(document).on("click", "[f='send_emailcode']", function(){
		$value = $("#email").val();
		if ($value.length == 0) {
			ToastShow("请填写有效的邮箱");
			return false;
		}
		$(this).html("获取中...");
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz&a=send",
			cache: false,
			data: {send_type:"email", name:$value, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("发送成功，请查收邮件！");
					_countDown("btn_send_emailcode", "send_emailcode");
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("发送失败，请检查邮箱");
					}
					$("#btn_send_emailcode").html("获取验证码");
				}
				

			},
			error: function() {
				$("#btn_send_emailcode").html("获取验证码");
			}
		});

	});

	//邮箱认证
	$(document).on("click", "[f='but_confirm_email_rz']", function(){
		$email = $("#email").val();
		$emailcode = $("#emailcode").val();
		if ($email.length == 0) {
			ToastShow("请填写邮箱地址");
			return false;
		}
		if ($emailcode.length == 0) {
			ToastShow("请填写邮箱验证码");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz",
			cache: false,
			data: {a:"emailrz", email:$email, emailcode:$emailcode, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("认证成功");
					_closeShadeBox(SHADE_BOX_ID, function(){
						window.location.reload();
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("认证失败，请检查！");
					}
				}
				

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


	//获取QQ号验证码
	$(document).on("click", "[f='send_qqcode']", function(){
		$value = $("#qq").val();
		if ($value.length == 0) {
			ToastShow("请填写QQ号");
			return false;
		}
		$(this).html("获取中...");
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz&a=send",
			cache: false,
			data: {send_type:"qq", name:$value, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("发送成功，请查收QQ邮件！");
					_countDown("btn_send_qqcode", "send_qqcode");
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("发送失败，请检查QQ邮箱");
					}
					$("#btn_send_qqcode").html("获取验证码");
				}
				

			},
			error: function() {
				$("#btn_send_qqcode").html("获取验证码");
			}
		});

	});

	//QQ认证
	$(document).on("click", "[f='but_confirm_qq_rz']", function(){
		$qq = $("#qq").val();
		$qqcode = $("#qqcode").val();
		if ($qq.length == 0) {
			ToastShow("请填写QQ号码");
			return false;
		}
		if ($qqcode.length == 0) {
			ToastShow("请填写QQ验证码");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz",
			cache: false,
			data: {a:"qqrz", qq:$qq, qqcode:$qqcode, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("认证成功");
					_closeShadeBox(SHADE_BOX_ID, function(){
						window.location.reload();
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("认证失败，请检查！");
					}
				}
				

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


	//上传图片
	$(document).on("change", "[f='but_rz_uploadimg']", function(){
		$_file_id = $(this).attr("id");
		$_my_obj = $(this);
		$_my_obj.parent().addClass("loading");
		$("#"+$_file_id+"_preview").hide();
		$.ajaxFileUpload({
			"url": _OE_FILE+"&c=index&a=upload",
			"secureuri": false,
			"fileElementId": $_file_id,
			"dataType": "json",
			"data": {
				uploadpart: $_file_id
			},
			async: this.async,
			beforeSend: function ($xmlobj) {},
			complete: function ($data) {},
			success: function ($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				$imgthumb = $json.thumbimg;
				$imgurl = $json.uploadimg;
				$attid = $json.attid;
				if (typeof($attid) == "undefined") {
					$attid = "";
				}
				
				$_my_obj.parent().removeClass("loading");
				if ($response == "1") { //成功
					_oeloveFileSynYun($attid); //同步云存储
					$("#"+$_file_id+"_preview").attr("src", $imgurl).show();
					$("#"+$_file_id+"_draw").val($imgurl);
				}
				else { //失败
					$error = "上传失败，请检查图片大小和格式！";
					if ($result.length > 0 ) {
						$error = $result;
					}
					ToastShow($error);
				}

			},
			error: function ($data, e, b) {
				$_my_obj.parent().removeClass("loading");
				ToastShow("上传失败，请检查图片大小和格式！");

			}
		});

	});

	//实名认证
	$(document).on("click", "[f='but_confirm_idnumber_rz']", function(){
		$truename = $("#truename").val();
		$idnumber = $("#idnumber").val();
		$paper1 = $("#img_1_draw").val();
		$paper2 = $("#img_2_draw").val();

		if ($truename.length == 0) {
			ToastShow("请填写真实姓名");
			return false;
		}
		if ($idnumber.length == 0) {
			ToastShow("请填写身份证号");
			return false;
		}
		if ($paper1.length == 0) {
			ToastShow("请上传身份证正面");
			return false;
		}
		if ($paper2.length == 0) {
			ToastShow("请上传身份证反面");
			return false;
		}

		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz",
			cache: false,
			data: {a:"idrz", truename:$truename, idnumber:$idnumber, paper1:$paper1, paper2:$paper2, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("提交成功，请等待审核");
					_closeShadeBox(SHADE_BOX_ID, function(){
						window.location.reload();
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("提交失败，请检查！");
					}
				}
				

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});

	
	//保存微信号 7.03.22
	$(document).on("click", "[f='but_save_weixin']", function(){
		$weixin = $("#weixin").val();
		if ($weixin.length == 0) {
			ToastShow("请填写微信号");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz&a=saveweixin",
			cache: false,
			data: {weixin:$weixin, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("编辑成功");
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("编辑失败");
					}
				}
			},
			error: function() {
			}
		});
	});


	//学历认证 7.03.23
	$(document).on("click", "[f='but_confirm_edu_rz']", function(){
		$img = $("#eimg_draw").val();
		if ($img.length == 0) {
			ToastShow("请上传学历证明");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz",
			cache: false,
			data: {a:"edurz", eduimg:$img, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("提交成功，请等待审核");
					_closeShadeBox(SHADE_BOX_ID, function(){
						window.location.reload();
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("提交失败，请检查！");
					}
				}
				

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});

	//房子认证 7.03.23
	$(document).on("click", "[f='but_confirm_house_rz']", function(){
		$img = $("#himg_draw").val();
		if ($img.length == 0) {
			ToastShow("请上传房产证明");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz",
			cache: false,
			data: {a:"houserz", houseimg:$img, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("提交成功，请等待审核");
					_closeShadeBox(SHADE_BOX_ID, function(){
						window.location.reload();
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("提交失败，请检查！");
					}
				}
				

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});

	//车子认证 7.03.23
	$(document).on("click", "[f='but_confirm_car_rz']", function(){
		$img = $("#cimg_draw").val();
		if ($img.length == 0) {
			ToastShow("请上传车子证明");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=rz",
			cache: false,
			data: {a:"carrz", carimg:$img, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("提交成功，请等待审核");
					_closeShadeBox(SHADE_BOX_ID, function(){
						window.location.reload();
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("提交失败，请检查！");
					}
				}
				

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


});



//倒计时
var cd_timer = 60; //1分钟
function _countDown(obj_id, attr_f) {
	$obj = $("#"+obj_id);
	if (cd_timer == 0) {
		$obj.html("获取验证码");
		$obj.removeClass("current");
		$obj.attr("f", attr_f);
		cd_timer = 60; 
	}
	else {
		$obj.removeClass("current");
		$obj.addClass("current"); 
		$obj.html(cd_timer+"秒重新发送");
		$obj.attr("f", "");
		cd_timer--; 
		setTimeout(function() { 
			_countDown(obj_id, attr_f)
		},	1000);
	}
}